<!--
 * @Description: 
 * @Author: ljl
 * @Date: 2024-11-14 10:48:53
 * @LastEditors: rendc
 * @LastEditTime: 2024-11-14 17:29:45
-->
<template>
  <div class="bg">
    <button>按钮</button>
    <el-button>按钮</el-button>
    <el-button type="danger">Danger</el-button>
    <!-- 注册组件 -->
    <Reg v-if="flag" @my-alert="myAlert" />
    <!-- 登录 -->
    <login v-if="!flag" />
    <p v-if="flag" @click="changeFlag">已有账号，直接<a href="">登录</a></p>
    <p v-if="!flag" @click="changeFlag">没有账号，立即<a href="">注册</a></p>

    <button @click="changeFlag">{{ flag ? '去登录页面' : '去注册页面' }}</button>
    <!-- 按钮的样式 -->
    <!-- type、plain、round 和 circle -->
    <!-- 写一个主要按钮 -->
    <el-button type="primary" :disabled="flag" plain round>主要按钮</el-button>
    <el-button type="primary" :loading="loading" @click="toLogin">登录</el-button>
    <br>
    <el-checkbox v-model="checked1" label="Option 1" size="large" />
    <el-checkbox v-model="checked2" label="Option 2" size="large" disabled />
<br><br><br><br>

    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="date" label="日期" width="180" />
      <el-table-column prop="name" label="名字" width="180" />
      <el-table-column prop="address" label="地址" />
      <el-table-column fixed="right" label="Operations" min-width="120">
        <template #default="scope">
          <el-button link type="primary" size="small" @click="handleClick(scope.row)">  Detail  </el-button>
          <el-button link type="primary" size="small">Edit</el-button>
          <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">  Delete  </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import Reg from './views/Reg.vue';
import Login from '@/views/Login.vue';
// flag 为 true 显示注册页面
// flag 为 false 显示登录页面
const flag = ref(true);
const loading = ref(false);
const checked1 = ref(true);
const checked2 = ref(true);
const tableData = ref([
  {
    date: '2016-05-03',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-02',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
]);

// 切换登录注册页面
function changeFlag () {
  flag.value = !flag.value;
}
// 父组件中声明的事件
function myAlert () {
  alert('我是父组件中的事件-myAlert');
}
// 登录
function toLogin () {
  loading.value = true;
  // 模拟登录请求
  setTimeout(() => {
    alert('登录成功');
    loading.value = false;
  }, 3000);
}
const handleClick = (row) => {
  console.log('🚀 - handleClick - row:', row);
  console.log('🚀 - handleClick - row.name:', row.name);
}
const handleDelete = (row) => {
  const index = tableData.value.findIndex(item => item.id === row.id);
  if (index !== -1) {
    dynamicValidateForm.domains.splice(index, 1)
  }
}

</script>
<style scoped>
.bg {
  /* background-image: url(./xxx.png); */
}
</style>